package org.jeecg.modules.zcgl.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.zcgl.entity.CustomerBalance;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Description: 客户余额信息
 * @Author: jeecg-boot
 * @Date:   2020-12-11
 * @Version: V1.0
 */
public interface CustomerBalanceMapper extends BaseMapper<CustomerBalance> {

    CustomerBalance selectCustomerIdAndCompanyId(@Param("companyId") String companyId, @Param("customerId") String customerId);

    CustomerBalance selectCustomerIdAndLeaseContractId(@Param("leaseContractId") String leaseContractId, @Param("customerId") String customerId);

    BigDecimal selectBalanceCustomerIdAndCompanyId(String companyId, String customerId);

    /**
     * 根据客户ID查询 并根据公司统计余额
     * @param customerId
     * @return
     */
    @Select("select id,customer_id,sum(balance) as balance,company_id,lease_contract_id from zcgl_customer_balance where customer_id=#{customerId} GROUP BY company_id")
    List<CustomerBalance> getByCustomerId(@Param("customerId") String customerId);
}
